<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use aliyun\cdn\Client;

class ToolsController extends Controller
{
    protected function index($code)
    {
        return "页面错误";
    }

    protected function GetClearCdnCache(Request $request)
    {
        if ($request->isMethod('post')) {
            $type = $request->input("type");
            $url = $request->input("url");

            $client = new Client([
                'accessKeyId' => 'LTAISBy9feW2t6qN',
                'accessSecret' => 'LtYuV8xFXOenkrViSkgTuW0cybUcp7'
            ]);

            $package = [
                'Action' => 'RefreshObjectCaches',
                'ObjectPath' => $url,
                'ObjectType' => $type,
            ];
            $response = $client->createRequest($package);
            $message = "OK";

        } else  {
            $message = null;
        }
        return view("tools.clearCdnCache")->with("message", $message);

    }
}
